package com.ruoyi.business.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.ruoyi.business.domain.ReceivingBillentry;
import com.ruoyi.business.service.ReceivingBillentryService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;
import java.util.List;

/**
 * 收货物料明细Controller
 *
 * @author ruoyi
 * @date 2024-08-25
 */
@RestController
@RequestMapping("/system/receiving_billentry")
public class ReceivingBillentryController extends BaseController {
    @Autowired
    private ReceivingBillentryService receivingBillentryService;

    /**
     * 查询收货物料明细列表
     */
    @PreAuthorize("@ss.hasPermi('system:receiving_billentry:list')")
    @GetMapping("/list")
    public TableDataInfo list(ReceivingBillentry receivingBillentry) {
        startPage();
        List<ReceivingBillentry> list = receivingBillentryService.queryList(receivingBillentry);
        return getDataTable(list);
    }

    /**
     * 导出收货物料明细列表
     */
    @PreAuthorize("@ss.hasPermi('system:receiving_billentry:export')")
    @Log(title = "收货物料明细", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ReceivingBillentry receivingBillentry) {
        List<ReceivingBillentry> list = receivingBillentryService.queryList(receivingBillentry);
        ExcelUtil<ReceivingBillentry> util = new ExcelUtil<ReceivingBillentry>(ReceivingBillentry.class);
        util.exportExcel(response, list, "收货物料明细数据");
    }

    /**
     * 获取收货物料明细详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:receiving_billentry:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(receivingBillentryService.getById(id));
    }

    /**
     * 获取收货物料明细详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:note:index')")
    @GetMapping(value = "/receiving/{receivingId}")
    public AjaxResult getReceiptInfo(@PathVariable("receivingId") String receivingId) {
        QueryWrapper<ReceivingBillentry> query = Wrappers.query();
        query.eq("receiving_id", receivingId);
        List<ReceivingBillentry> list = receivingBillentryService.list(query);
        return success(list);
    }

    /**
     * 新增收货物料明细
     */
    @PreAuthorize("@ss.hasPermi('system:receiving_billentry:add')")
    @Log(title = "收货物料明细", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ReceivingBillentry receivingBillentry) {
        return toAjax(receivingBillentryService.save(receivingBillentry));
    }

    /**
     * 修改收货物料明细
     */
    @PreAuthorize("@ss.hasPermi('system:receiving_billentry:edit')")
    @Log(title = "收货物料明细", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ReceivingBillentry receivingBillentry) {
        return toAjax(receivingBillentryService.updateById(receivingBillentry));
    }

    /**
     * 删除收货物料明细
     */
    @PreAuthorize("@ss.hasPermi('system:receiving_billentry:remove')")
    @Log(title = "收货物料明细", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(receivingBillentryService.removeByIds(Arrays.asList(ids)));
    }
}

